﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.Plumbing
{
	public partial class FormParasSetting : System.Windows.Forms.Form
	{
		public FormParasSetting()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = (base.Icon = Resource.YArchitechIcon);
			this.InitCombBox();
			this.InitParameterSetting();
		}

		private void btnHelp_Click(object sender, EventArgs e)
		{
			YJKMessageBox.Information("宿舍(I、II类)、住宅、宾馆、酒店式公寓、医院、疗养院、幼儿园、养老院的卫生间 1.5\r\n旅馆和其它公共建筑的公共盥洗室和厕所间 2.0～2.5");
		}

		private void InitCombBox()
		{
			this.combGuanCai.Items.Add("金属管");
			this.combGuanCai.Items.Add("塑料管");
			this.combGuanCai.SelectedIndex = 0;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.hyCalParameter = new HYCalParameter();
			int selectedIndex = this.combGuanCai.SelectedIndex;
			if (selectedIndex != 0)
			{
				if (selectedIndex == 1)
				{
					this.hyCalParameter.nMaterType = 1;
				}
			}
			else
			{
				this.hyCalParameter.nMaterType = 0;
			}
			if (!(this.tbn.Text != ""))
			{
				YJKMessageBox.Information("参数不能为空");
				return;
			}
			this.hyCalParameter.n = double.Parse(this.tbn.Text);
			this.calDrainData = new CalDrainData();
			if (this.tbarfa.Text != "")
			{
				this.calDrainData.dα = double.Parse(this.tbarfa.Text);
				if (this.radioButton1.Checked)
				{
					this.calDrainData.nFormula = 0;
				}
				else
				{
					this.calDrainData.nFormula = 1;
				}
				this.UserSettingWrite();
				base.DialogResult = DialogResult.OK;
				return;
			}
			YJKMessageBox.Information("参数不能为空");
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void InitParameterSetting()
		{
			this.dic = this.userSetting.GetDrainageCalSetting();
			this.tbarfa.Text = this.userSetting.GetValueFromDic("alfab", "1.5", this.dic);
			this.tbn.Text = this.userSetting.GetValueFromDic("n", "0.011", this.dic);
			this.combGuanCai.SelectedIndex = int.Parse(this.userSetting.GetValueFromDic("nMaterType", "0", this.dic));
			if (this.userSetting.GetValueFromDic("nFormula", "0", this.dic) == "0")
			{
				this.radioButton1.Checked = true;
				return;
			}
			this.radioButton2.Checked = true;
		}

		private void UserSettingWrite()
		{
			try
			{
				Dictionary<string, string> dictionary = new Dictionary<string, string>();
				dictionary.Add("alfab", this.tbarfa.Text);
				if (this.radioButton1.Checked)
				{
					dictionary.Add("nFormula", "0");
				}
				else
				{
					dictionary.Add("nFormula", "1");
				}
				dictionary.Add("nMaterType", this.combGuanCai.SelectedIndex.ToString());
				dictionary.Add("n", this.tbn.Text);
				this.userSetting.WriteDrainageCalSetting(dictionary);
			}
			catch (Exception)
			{
			}
		}

		private void combGongShi_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		public HYCalParameter hyCalParameter;

		public CalDrainData calDrainData;

		private HVACUserSetting userSetting = new HVACUserSetting();

		private Dictionary<string, string> dic;
	}
}
